<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>resin安装与配置 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>resin安装与配置</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Saltstack/">Saltstack</a>
			</span>
		
	</div>

	

	
		<h2 id="1-saltstack安装"><a href="#1-saltstack安装" class="headerlink" title="1.saltstack安装"></a>1.saltstack安装</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;准备两台机器 192.168.0.84  192.168.0.83</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;设置hostname</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.84</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/sysconfig/network</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/01.png?raw=true" alt="01"><figcaption class="figure__caption">01</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.83</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># vim /etc/sysconfig/network</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/02.png?raw=true" alt="02"><figcaption class="figure__caption">02</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;配置hosts </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.84</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/hosts</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/03.png?raw=true" alt="03"><figcaption class="figure__caption">03</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.83</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># vim /etc/hosts</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/04.png?raw=true" alt="04"><figcaption class="figure__caption">04</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;关闭selinux，清空iptables规则</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.84：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># yum install -y epel-release</span></div><div class="line">[root@web9 ~]<span class="comment"># yum install -y salt-master salt-minion</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.83：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># yum install -y epel-release</span></div><div class="line">[root@web10 ~]<span class="comment"># yum install -y salt-minion</span></div></pre></td></tr></table></figure>
<h3 id="启动服务"><a href="#启动服务" class="headerlink" title="启动服务"></a>启动服务</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.84上：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑配置文件 /etc/salt/minion </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/salt/minion</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;大概16行修改或增加    </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">master: 192.168.0.84</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/05.png?raw=true" alt="05"><figcaption class="figure__caption">05</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;启动服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># service salt-master start</span></div><div class="line">Starting salt-master daemon: [确定]</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># service salt-minion start</span></div><div class="line">Starting salt-minion daemon: [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.83上：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑配置文件 /etc/salt/minion </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># vim /etc/salt/minion</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;大概16行修改或增加</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">master: 192.168.0.84</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/06.png?raw=true" alt="06"><figcaption class="figure__caption">06</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;启动服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># service salt-minion start</span></div><div class="line">Starting salt-minion daemon: [确定]</div></pre></td></tr></table></figure>
<h3 id="配置认证"><a href="#配置认证" class="headerlink" title="配置认证"></a>配置认证</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;以下操作都是在192.168.0.84上：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/07.png?raw=true" alt="07"><figcaption class="figure__caption">07</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;现在要把 web10 加到 Accepted Keys</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># salt-key -a web10.yanyi.com</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/08.png?raw=true" alt="08"><figcaption class="figure__caption">08</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;此时我们在client的 /etc/salt/pki/minion 目录下面会多出一个minion_master.pub 文件</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/09.png?raw=true" alt="09"><figcaption class="figure__caption">09</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;可以使用 salt-key 命令查看到已经签名的客户端</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;salt-key 可以使用-A签名所有主机，也可以使用-d删除指定主机的key，-D删除所有主机。</p>
<h3 id="远程执行命令"><a href="#远程执行命令" class="headerlink" title="远程执行命令"></a>远程执行命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例1： salt ‘<em>‘ test.ping    这里的</em>表示所以已经签名的客户端，也可以指定其中一个，比如web10.yanyi.com</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/10.png?raw=true" alt="10"><figcaption class="figure__caption">10</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例2:  salt ‘*’ cmd.run   ‘df -h’</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/11.png?raw=true" alt="11"><figcaption class="figure__caption">11</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明： 这里的<em>必须是在master上已经被接受过的客户端，可以通过salt-key查到，通常是我们已经设定的id值。关于这部分内容，它支持通配、列表以及正则。 比如两台客户端  web10  web11， 那我们可以写成  salt ‘web</em>’    salt ‘web1[01]’   salt -L ‘web10,web11’   salt -E ‘web(10|11) 等形式，使用列表，即多个机器用 逗号分隔，而且需要加-L，使用正则必须要带-E选项&gt;。 它还支持grains，加-G选项，     pillar 加-I选项，下面会介绍到。</p>
<h2 id="2-saltstack-grains"><a href="#2-saltstack-grains" class="headerlink" title="2.saltstack grains"></a>2.saltstack grains</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;grains是在minion启动时收集到的一些信息，比如操作系统类型、网卡ip、内核版本、cpu架构等。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;salt ‘web10.yanyi.com’ grains.ls 列出所有的grains项目名字</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># salt 'web10.yanyi.com' grains.ls</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/12.png?raw=true" alt="12"><figcaption class="figure__caption">12</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;salt ‘web10.yanyi.com’ grains.items 列出所有grains项目以及值</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># salt 'web10.yanyi.com' grains.items</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/13.png?raw=true" alt="13"><figcaption class="figure__caption">13</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;grains的信息并不是动态的，并不会时时变更，它只是在minion启动时收集到的。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;我们可以根据grains收集到的一些信息，做配置管理工作。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;grains支持自定义信息。</p>
<h3 id="自定义-grains"><a href="#自定义-grains" class="headerlink" title="自定义 grains"></a>自定义 grains</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.83上，编辑文件 /etc/salt/grains </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># vim /etc/salt/grains</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">role: nginx</div><div class="line">env: <span class="built_in">test</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/14.png?raw=true" alt="14"><figcaption class="figure__caption">14</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;重启minion服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web10 ~]<span class="comment"># service salt-minion restart</span></div><div class="line">Stopping salt-minion daemon:               [确定]</div><div class="line">Starting salt-minion daemon:               [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.84上：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;获取 grains：salt ‘*’ grains.item role env</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># salt '*' grains.item role env</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/15.png?raw=true" alt="15"><figcaption class="figure__caption">15</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;可以借助grains的一些属性信息来执行</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># salt -G role:nginx cmd.run 'hostname'</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/16.png?raw=true" alt="16"><figcaption class="figure__caption">16</figcaption></figure></p>
<h2 id="3-saltstack-pillar"><a href="#3-saltstack-pillar" class="headerlink" title="3.saltstack pillar"></a>3.saltstack pillar</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;pillar和grains不一样，是在master上定义的，并且是针对minion定义的一些信息。像一些比较重要的数据（密码）可以存在pillar里，还可以定义变量等。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;配置自定义pillar  /etc/salt/master</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/salt/master</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;找到如下配置：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/17.png?raw=true" alt="17"><figcaption class="figure__caption">17</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;去掉前面的警号</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/18.png?raw=true" alt="18"><figcaption class="figure__caption">18</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建此目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># mkdir /srv/pillar</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 /srv/pillar/test.sls </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/pillar/test.sls</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;内容如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">conf: /etc/123.conf</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/19.png?raw=true" alt="19"><figcaption class="figure__caption">19</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 /srv/pillar/top.sls  </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/pillar/top.sls</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;内容如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">base:</div><div class="line">  <span class="string">'web10.yanyi.com'</span>:</div><div class="line">    - <span class="built_in">test</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/20.png?raw=true" alt="20"><figcaption class="figure__caption">20</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;重启master</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># service salt-master restart</span></div><div class="line">Stopping salt-master daemon: [确定]</div><div class="line">Starting salt-master daemon: [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;当更改完pillar配置文件后，我们可以通过刷新pillar配置来获取新的pillar状态：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;salt ‘*’ saltutil.refresh_pillar</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/21.png?raw=true" alt="21"><figcaption class="figure__caption">21</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;验证：salt  ‘*’ pillar.item conf</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/22.png?raw=true" alt="22"><figcaption class="figure__caption">22</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;pillar同样可以用来作为salt的匹配对象。比如 salt  -I ‘conf:/etc/123.conf’  test.ping</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/23.png?raw=true" alt="23"><figcaption class="figure__caption">23</figcaption></figure></p>
<h2 id="4-配置管理安装-apache"><a href="#4-配置管理安装-apache" class="headerlink" title="4.配置管理安装 apache"></a>4.配置管理安装 apache</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.84上，编辑配置文件 /etc/salt/master</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /etc/salt/master</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;搜索找到 file_roots</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/24.png?raw=true" alt="24"><figcaption class="figure__caption">24</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;打开如下内容的注释：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/25.png?raw=true" alt="25"><figcaption class="figure__caption">25</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建 /stv/salt 目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># mkdir /srv/salt</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 /srv/salt/top.sls </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/top.sls</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;加入如下内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">base:</div><div class="line">  <span class="string">'*'</span>:</div><div class="line">    - apache</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/26.png?raw=true" alt="26"><figcaption class="figure__caption">26</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;意思是，在所有的客户端上执行 apache模块</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;重启 /etc/init.d/salt-master restart</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># service salt-master restart </span></div><div class="line">Stopping salt-master daemon: [确定]</div><div class="line">Starting salt-master daemon: [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 /srv/salt/apache.sls </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/apache.sls</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;加入如下内容，这个就是apache模块的内容</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这里如果只有一个服务，那么就可以写成 –name: httpd 不用再换一行了。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">apache-service:</div><div class="line">  pkg.installed:</div><div class="line">    - names: </div><div class="line">      - httpd</div><div class="line">      - httpd-devel</div><div class="line">  service.running:</div><div class="line">    - name: httpd</div><div class="line">    - <span class="built_in">enable</span>: True</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/27.png?raw=true" alt="27"><figcaption class="figure__caption">27</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明，apache-service是id的名字，自定义的。pkg.installed 为包安装函数，下面是要安装的包的名字。service.running也是一个函数，来保证指定的服务启动，enable表示开机启动。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;执行： salt ‘web10.yanyi.com’ state.highstate</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/28.png?raw=true" alt="28"><figcaption class="figure__caption">28</figcaption></figure></p>
<h2 id="5-配置文件和目录管理"><a href="#5-配置文件和目录管理" class="headerlink" title="5.配置文件和目录管理"></a>5.配置文件和目录管理</h2><h3 id="配置管理文件"><a href="#配置管理文件" class="headerlink" title="配置管理文件"></a>配置管理文件</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/filetest.sls</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">file_test:</div><div class="line">  file.managed:</div><div class="line">    - name: /tmp/yanyi.com</div><div class="line">    - <span class="built_in">source</span>: salt://<span class="built_in">test</span>/123/1.txt</div><div class="line">    - user: root</div><div class="line">    - group: root</div><div class="line">    - mode: 644</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/29.png?raw=true" alt="29"><figcaption class="figure__caption">29</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：第一行的file_test为自定的名字，表示该配置段的名字，可以在别的配置段中引用它，source指定文件从哪里拷贝，这里的test相当于是/srv/salt/test</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># mkdir /srv/salt/test</span></div><div class="line">[root@web9 ~]<span class="comment"># mkdir /srv/salt/test/123</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;更改 top.sls </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/top.sls</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/30.png?raw=true" alt="30"><figcaption class="figure__caption">30</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端刷新</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># salt 'web10.yanyi.com' state.highstate</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/31.png?raw=true" alt="31"><figcaption class="figure__caption">31</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;客户端查看</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/32.png?raw=true" alt="32"><figcaption class="figure__caption">32</figcaption></figure></p>
<h3 id="配置管理目录"><a href="#配置管理目录" class="headerlink" title="配置管理目录"></a>配置管理目录</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/dirtest.sls</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加内容    </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">file_dir:</div><div class="line">  file.recurse:</div><div class="line">    - name: /tmp/testdir</div><div class="line">    - <span class="built_in">source</span>: salt://<span class="built_in">test</span>/123</div><div class="line">    - user: root</div><div class="line">    - file_mode: 644</div><div class="line">    - dir_mode: 755</div><div class="line">    - mkdir: True</div><div class="line">    - clean: True</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/33.png?raw=true" alt="33"><figcaption class="figure__caption">33</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>clean: True</strong> 加上它之后，源删除文件或目录，目标也会跟着删除，否则不会删除</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;参考  <a href="http://www.0550go.com/automation-deployment/saltstack/saltstack-file-recurse.html" target="_blank" rel="external">http://www.0550go.com/automation-deployment/saltstack/saltstack-file-recurse.html</a></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 top.sls</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/top.sls</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加内容</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/34.png?raw=true" alt="34"><figcaption class="figure__caption">34</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端刷新</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># salt 'web10.yanyi.com' state.highstate</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/35.png?raw=true" alt="35"><figcaption class="figure__caption">35</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;查看客户端</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/36.png?raw=true" alt="36"><figcaption class="figure__caption">36</figcaption></figure></p>
<h2 id="6-配置管理远程命令"><a href="#6-配置管理远程命令" class="headerlink" title="6.配置管理远程命令"></a>6.配置管理远程命令</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/cmdtest.sls</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">cmd_test:</div><div class="line">  cmd.run:</div><div class="line">    - onlyif: <span class="built_in">test</span> -f /tmp/111.txt</div><div class="line">    - names:</div><div class="line">      - touch /tmp/111.txt</div><div class="line">      - mkdir /tmp/1233</div><div class="line">    - user: root</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/37.png?raw=true" alt="37"><figcaption class="figure__caption">37</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;还可以加unless，和onlyif正好相反</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 top.sls</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/top.sls</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/38.png?raw=true" alt="38"><figcaption class="figure__caption">38</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端刷新</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># salt 'web10.yanyi.com' state.highstate</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/39.png?raw=true" alt="39"><figcaption class="figure__caption">39</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;查看客户端</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/40.png?raw=true" alt="40"><figcaption class="figure__caption">40</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;重新修改配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/cmdtest.sls</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">cmd_test:</div><div class="line">  cmd.run:</div><div class="line">    - unless: <span class="built_in">test</span> -f /tmp/111.txt</div><div class="line">    - names:</div><div class="line">      - touch /tmp/111.txt</div><div class="line">      - mkdir /tmp/1233</div><div class="line">    - user: root</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/41.png?raw=true" alt="41"><figcaption class="figure__caption">41</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端刷新</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># salt 'web10.yanyi.com' state.highstate</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/42.png?raw=true" alt="42"><figcaption class="figure__caption">42</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;查看客户端</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/43.png?raw=true" alt="43"><figcaption class="figure__caption">43</figcaption></figure></p>
<h2 id="7-配置管理远程脚本"><a href="#7-配置管理远程脚本" class="headerlink" title="7.配置管理远程脚本"></a>7.配置管理远程脚本</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/shelltest.sls</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">shell_test:</div><div class="line">  cmd.script:</div><div class="line">    - <span class="built_in">source</span>: salt://<span class="built_in">test</span>/1.sh</div><div class="line">    - user: root</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/44.png?raw=true" alt="44"><figcaption class="figure__caption">44</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑脚本文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/test/1.sh</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#!/bin/bash</span></div><div class="line">touch /tmp/111.txt</div><div class="line"><span class="keyword">if</span> [ -d /tmp/1233 ]</div><div class="line"><span class="keyword">then</span></div><div class="line">    rm -rf /tmp/1233</div><div class="line"><span class="keyword">else</span></div><div class="line">    mkdir /tmp/1233</div><div class="line"><span class="keyword">fi</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/45.png?raw=true" alt="45"><figcaption class="figure__caption">45</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 top.sls</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/top.sls</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/46.png?raw=true" alt="46"><figcaption class="figure__caption">46</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端刷新</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># salt 'web10.yanyi.com' state.highstate</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/47.png?raw=true" alt="47"><figcaption class="figure__caption">47</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;客户端查看</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/48.png?raw=true" alt="48"><figcaption class="figure__caption">48</figcaption></figure></p>
<h2 id="8-配置管理任务计划"><a href="#8-配置管理任务计划" class="headerlink" title="8.配置管理任务计划"></a>8.配置管理任务计划</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/crontest.sls</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">cron_test:</div><div class="line">  cron.present:</div><div class="line">    - name: /bin/touch /tmp/111.txt</div><div class="line">    - user: root</div><div class="line">    - minute: <span class="string">'*'</span></div><div class="line">    - hour: 20</div><div class="line">    - daymonth: <span class="string">'*'</span></div><div class="line">    - month: <span class="string">'*'</span></div><div class="line">    - dayweek: <span class="string">'*'</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/49.png?raw=true" alt="49"><figcaption class="figure__caption">49</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注意，*需要用单引号引起来。当然我们还可以使用file.managed模块来管理cron，因为系统的cron都是以配置文件的形式存在的。想要删除该cron，需要增加：<br>cron.absent:</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;- name: /bin/touch /tmp/111.txt</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;两者不能共存，要想删除一个cron，那之前的present就得去掉。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 top.sls</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># vim /srv/salt/top.sls</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/50.png?raw=true" alt="50"><figcaption class="figure__caption">50</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务端刷新</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># salt 'web10.yanyi.com' state.highstate</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/51.png?raw=true" alt="51"><figcaption class="figure__caption">51</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;客户端查看</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/52.png?raw=true" alt="52"><figcaption class="figure__caption">52</figcaption></figure></p>
<h2 id="9-saltstack-几个常用的命令"><a href="#9-saltstack-几个常用的命令" class="headerlink" title="9.saltstack 几个常用的命令"></a>9.saltstack 几个常用的命令</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cp.get_file  拷贝master上的文件到客户端</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># salt 'web10.yanyi.com' cp.get_file salt://apache.sls /tmp/yanyi.com</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/53.png?raw=true" alt="53"><figcaption class="figure__caption">53</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cp.get_dir 拷贝目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@web9 ~]<span class="comment"># salt 'web10.yanyi.com' cp.get_dir salt://test /tmp/yanyi</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/54.png?raw=true" alt="54"><figcaption class="figure__caption">54</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;会自动在客户端创建test目录，所以后面不要加test，如果写成 /tmp/yanyi/  则会在/tmp/yanyi/目录下又创建test</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;salt-run manage.up  显示存活的minion</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/55.png?raw=true" alt="55"><figcaption class="figure__caption">55</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;salt ‘*’ cmd.script salt://test/1.sh  命令行下执行master上的shell脚本</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/Saltstack%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/56.png?raw=true" alt="56"><figcaption class="figure__caption">56</figcaption></figure></p>

	

	
		<span class="different-posts"><a href="/2017/10/12/Saltstack/1. Saltstack 安装配置/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
